package servlet.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import member.domain.Member;

/*
 * Listener class
 *  - 1. Listener Interface를 implements
 *  	(ServerContextEvent처리 - ServerContextListener)
 *  - 2. web.xml에 등록 <listener></listener-class>
 */
public class MyListener implements ServletContextListener{

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		//Application 종료 시점에 호출
		ServletContext ctx = arg0.getServletContext();
		Member admin = (Member)ctx.getAttribute("admin");
		System.out.println("---------------------");
		System.out.println(admin);
		System.out.println("myservlet 어플리케이션 종료");
		System.out.println("---------------------");
	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		//Application 시작 시점에 호출
		//application scope에 속성을 biding - ServletConxtext
		ServletContext ctx = arg0.getServletContext();
		ctx.setAttribute("admin", new Member("admin_id", "1111", "관리자", "admin@abc.com", 0));
		
		System.out.println("---------------------");
		System.out.println("myservlet 어플리케이션 시작");
		System.out.println("---------------------");
	}
}
